package com.yhgm.service.impl;

import com.yhgm.mapper.SystemLogDao;
import com.yhgm.service.SystemLogService;
import com.yhgm.utils.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class SystemLogServiceImpl implements SystemLogService {
    @Resource
    private SystemLogDao systemLogDao;

    @Override
    public R clear() {
        return R.error("管理员取消了清空所有日志的功能");
//        if (systemLogDao.clear() > 0) {
//            return R.ok("日志已清空");
//        } else {
//            return R.error("日志清空失败");
//        }
    }

    @Override
    public R getAll(Integer code,String msg,Integer page, Integer size) {
        if (page < 1) {
            return R.error("page couldn't less than 1");
        } else {
            page = (page - 1) * size;
            Map<String, Object> data = new HashMap<>();
            data.put("list", systemLogDao.findAll(code,msg,page, size));
            data.put("total", systemLogDao.count(code,msg));
            return R.ok(data, "getProjectList");
        }
    }

    @Override
    public R clearThreeMonth() {
        systemLogDao.clearThreeMonth();
        return R.ok("已清除三个月前的日志");
    }
}
